package atguigu.neibulei;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CommonReport {

	public static void main(String[] args) {
		
		CommonReport report = new CommonReport();
		report.sort();
		
		
	}
	
	
	public void sort() {
		
		List<String> sampleList = new ArrayList<String>();
		sampleList.add("20220101K");
		sampleList.add("20220103K");
		sampleList.add("20220102K");
		sampleList.add("20220104K");
		sampleList.add("20220106K");
		sampleList.add("20220105K");
		
		// 在成员方法中可以直接使用内部类对象，直接new就可以了。
		Collections.sort(sampleList, new SampleNumberComparator());
		
		sampleList.stream().forEach(System.out::println);
		
	}
	
	class SampleNumberComparator implements Comparator<String>{
        @Override
        public int compare(String o1, String o2) {
            String str1 = o1.replaceAll("[a-zA-Z#]","");
            String str2 = o2.replaceAll("[a-zA-Z#]","");
            try {
                int i = Integer.parseInt(str1);
                int i1 = Integer.parseInt(str2);
                if(i>i1) return 1;
                else if(i < i1) return -1;
                else return 0;
            }catch (Exception e){
            	e.printStackTrace();
            }
            return 0;
        }
    }
}
